﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

namespace BBICMS.Repository
{
    public interface IRepository<T> where T : class
    {
        IEnumerable<T> All();
        IQueryable<T> GetAll();
        IQueryable<T> GetAll(params Expression<Func<T, object>>[] includes);
        IEnumerable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        Task<IEnumerable<T>> FindByAsync<KProperty>(Expression<Func<T, bool>> filter, Expression<Func<T, KProperty>> orderByExpression, bool ascending,
          CancellationToken cancellationToken = default(CancellationToken),
          params Expression<Func<T, object>>[] includes);
        T GetFirstOrDefault(Expression<Func<T, bool>> filter, params Expression<Func<T, object>>[] includes);
        Task<T> GetFirstOrDefaultAsync(Expression<Func<T, bool>> filter, CancellationToken cancellationToken = default(CancellationToken), params Expression<Func<T, object>>[] includes);

        IEnumerable<T> GetFilteredElements(Expression<Func<T, bool>> filter);
        IEnumerable<T> GetFilteredElements(Expression<Func<T, bool>> filter, params Expression<Func<T, object>>[] includes);
        T GetById(object id);
        void Add(T entity);
        void Update(T entity);
        void Delete(T entity);
        void Delete(int id);
        void Detach(T entity);
        IEnumerable<T> GetPagedElements<KProperty>(int pageIndex, int pageSize,
           Expression<Func<T, KProperty>> orderByExpression, bool ascending);

        IEnumerable<T> GetPagedElements<KProperty>(int pageIndex, int pageSize,
           Expression<Func<T, KProperty>> orderByExpression, bool ascending,
           params Expression<Func<T, object>>[] includes);

        IEnumerable<T> GetPagedElements<KProperty>(int pageIndex, int pageSize,
           Expression<Func<T, KProperty>> orderByExpression, Expression<Func<T, bool>> filter, bool ascending,
           params Expression<Func<T, object>>[] includes);
    }
}
